﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace EngineOfEvermore.Scene.Physics
{
    public class CollisionSubSystem : SceneSubSystem
    {
        LinkedList<CollisionComponent> _collisionComponents = new LinkedList<CollisionComponent>();
        LinkedList<SensorComponent> _sensorComponents = new LinkedList<SensorComponent>();
        InternalPhysicsManager _physicsManager;

        internal CollisionSubSystem( InternalPhysicsManager physicsManager )
        {
            Debug.Assert( physicsManager != null );
            _physicsManager = physicsManager;
        }

        internal void RegisterCollisionComponent( CollisionComponent c )
        {
            Debug.Assert( !_collisionComponents.Contains( c ) );

            _collisionComponents.AddFirst( c );
            _physicsManager.RegisterCollisionComponent( c );
        }

        internal void UnregisterCollisionComponent( CollisionComponent c )
        {
            Debug.Assert( _collisionComponents.Contains( c ) );

            _physicsManager.UnregisterCollisionComponent( c );
            _collisionComponents.Remove( c );
        }

        public bool IsCollisionComponentRegistered( CollisionComponent c )
        {
            return _collisionComponents.Contains( c );
        }

        internal void RegisterSensorComponent( SensorComponent c )
        {
            Debug.Assert( !_sensorComponents.Contains( c ) );

            _sensorComponents.AddFirst( c );
            _physicsManager.RegisterSensorComponent( c );
        }

        internal void UnregisterSensorComponent( SensorComponent c )
        {
            Debug.Assert( _sensorComponents.Contains( c ) );

            _physicsManager.UnregisterSensorComponent( c );
            _sensorComponents.Remove( c );
        }

        public bool IsSensorComponentRegister( SensorComponent c )
        {
            return _sensorComponents.Contains( c );
        }
    }
}
